package mobi.hami.huapin.config;

import mobi.hami.huapin.cache.SpyMemcachedManager;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.BinaryConnectionFactory;
import net.spy.memcached.MemcachedClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * 类说明
 *
 * @author 阿飞 jijunjian@hami.mobi
 * @date 2018/5/28 18:25
 */
@Configuration
public class SpymemcacheConfiguration {

    private static final Logger logger = LoggerFactory.getLogger(SpymemcacheConfiguration.class);

    @Autowired
    private MemcacheConfig memcacheConfigconfig ;

    @Bean
    public SpyMemcachedManager getSpyMemcachedManager()
    {
        SpyMemcachedManager memcachedManager = new SpyMemcachedManager();

        try {


            logger.info("******************************************缓存配置中："+memcacheConfigconfig.servers);

            MemcachedClient memcachedClient=new MemcachedClient(
                    new BinaryConnectionFactory(),
                    AddrUtil.getAddresses(memcacheConfigconfig.servers));

            memcachedManager.setMemcachedClient(memcachedClient);

        } catch (IOException e) {
            e.printStackTrace();
        }

        return  memcachedManager;

    }

}
